package com.lg.okframe.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lg.okframe.R;
import com.lg.okframe.adapter.HomeAdapter;
import com.lg.okframe.adapter.RecruitAdapter;
import com.lg.okframe.base.BaseFragment;
import com.lg.okframe.entities.HomeData;
import com.lg.okframe.presenter.HomePresenter;
import com.lg.okframe.presenter.RecruitPresenter;
import com.lg.okframe.utils.view.ToastUtil;
import com.scwang.smartrefresh.header.WaterDropHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 招聘页面
 * Created by LG on 2018/7/31.
 */
public class RecruitFragment extends BaseFragment  {

    private List list_path;
    private List list_title;
    private Banner banner;
    List<HomeData.DataBean.GuanggaoBean> guanggao_parent = new ArrayList<>();
    private RecyclerView recruit_re;
    Context context;
    private SmartRefreshLayout refreshLayout;
    private RecruitPresenter homePresenter = new RecruitPresenter(this);

    @Override
    public void initData(Bundle savedInstanceState, Context context) {
        this.context = context;
        homePresenter.getHomeData();
    }


    public void setData(HomeData.DataBean homeData) {
        if (homeData != null) {
            List<HomeData.DataBean.GuanggaoBean> guanggao = homeData.getGuanggao();
            guanggao_parent.addAll(guanggao);
            guanggao_parent.addAll(guanggao);
            guanggao_parent.addAll(guanggao);
            recruit_re.setAdapter(new RecruitAdapter(guanggao_parent, context, this));
        } else {
            ToastUtil.show(getActivity(), "加载出错");
        }
        refreshLayout.finishRefresh();
    }

    @Override
    public void initView(View view, Context context) {
        recruit_re = (RecyclerView) view.findViewById(R.id.recruit_re);
        recruit_re.setLayoutManager(new LinearLayoutManager(getActivity()));
        refreshLayout = (SmartRefreshLayout) view.findViewById(R.id.recruit_re_reswsm);
        refreshLayout.setEnableLoadmore(true);
        refreshLayout.setRefreshHeader(new WaterDropHeader(getActivity()));
//        initBanner(banner);
    }

    @Override
    public int setView() {
        return R.layout.recruit_fragment;
    }


    //自定义的图片加载器
    private class MyLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load((String) path).into(imageView);
        }
    }


}
